<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/resources/css/public.css" media="all"/>
    <style>
        body {
            background-color: #f1f8ec;
            font-family: Arial, sans-serif;
        }

        h1 {
            color: #4CAF50;
            text-align: center;
        }

        form {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
            max-width: 500px;
            margin: 0 auto;
        }

        label {
            display: block;
            margin-bottom: 10px;
        }

        input[type=text], input[type=password] {
            padding: 5px;
            border-radius: 5px;
            border: none;
            box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
            width: auto;
        }

        input[type=button] {
            padding: 10px;
            background-color: #4CAF50;
            border: none;
            color: #fff;
            border-radius: 5px;
            cursor: pointer;
        }

        input[type=button]:hover {
            background-color: #3e8e41;
        }
    </style>
</head>
<body>
<!--没有加name属性，导致我找了半天的错误！-->
<a href="/sys/toIndex" class="layui-btn" style="margin-top: 10px;margin-left: 10px;">返回后台主页</a>
<h1>修改密码</h1>


<form class="layui-form layui-row changePwd" method="post" id="frm">
        <div class="layui-input-block layui-red pwdTips">请输入旧密码，新密码必须两次输入一致才能提交</div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
<!--                <input type="text" disabled class="layui-input layui-disabled">-->
                <input type="text" class="layui-input" id="username" name="username">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" value="" id="oldPwd" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd" name="oldPwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" value="" id="newPwd" placeholder="请输入新密码" lay-verify="required|newPwd" class="layui-input pwd" name="newPwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" value="" id="confirmPwd" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="changePwd" id="changePwd">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>

<div id="message"></div>

<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script>

    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

        form.verify({
            newPwd : function(value, item){
                if(value.length < 6){
                    return "密码长度不能小于6位";
                }
            },
            confirmPwd : function(value, item){
                if(value !== $('#newPwd').val()){
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        })

        form.on('submit(changePwd)', function(data) {
            $.post("/changePwd/true",data.field,function (rs){
                if(rs.code === -1){
                    layer.msg(rs.msg);
                }
                else{
                    layer.msg(rs.msg);
                    location.href = "/sys/toLogin";
                    layer.msg("请重新登录！");
                }
            })
            return false;
        });
    })
</script>

</body>
</html>
